﻿using MediatR;
using WarehouseManagement.Application.Command.WarehouseTypeCommand;
using WarehouseManagement.Infrstructre.Interface;

namespace WarehouseManagement.Application.CommandHandler.WareTypeCommandHandler
{
    /// <summary>
    /// 仓库分类删除
    /// </summary>
    public class DelWreTypeCommand:IRequestHandler<DelWareTypeCommand,int>
    {

        private readonly IWareTypeRepository _repository;

        public  DelWreTypeCommand(IWareTypeRepository repository)
        {
            _repository = repository;
        }

        public async Task<int> Handle(DelWareTypeCommand request, CancellationToken cancellationToken)
        {
            var res = (await _repository.GetAll()).Where(x=>request.Wid.Contains(x.WarehouseCategoryId)).ToList();
            foreach (var item in res)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _repository.UpdateAsync(item);
            }
            
            return 1;
        }
             
    }
}
